﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using STDTO.DataTransferObjects.Unit.Tests.Interfaces;
using STDTO.DataTransferObjects.Base;
using STDTO.DataTransferObjects.Interfaces;
using System.Runtime.Serialization;
using Microsoft.Practices.Unity;

namespace STDTO.DataTransferObjects.Unit.Tests.DTOs
{
    [DataContract]
    public class SimpleObjectDto : UnitySelfTrackingDataTransferObjectBase<ISimpleObject>, ISimpleObject
    {
        public SimpleObjectDto(IUnityContainer unityContainer) : base(unityContainer) { }
        #region ISimpleObject Members
        [DataMember]
        private int _Id;
        [DataMember]
        private string _Name;

        public int Id
        {
            get
            {
                return _Id;
            }
            set
            {
                Set("Id", ref _Id, value);
            }
        }
        
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                Set("Name", ref _Name, value);
            }
        }

        #endregion

        protected override void SpecificPopulate(ISimpleObject entity, IDataTrasferObjectToEntityMapper dataTrasferObjectToEntityMapper)
        {
            _Id = entity.Id;
            _Name = entity.Name;
        }

        protected override void SpecificGetValue(ISimpleObject entity, bool getOriginalValue, IDataTrasferObjectToEntityMapper dataTrasferObjectToEntityMapper)
        {
            entity.Id = RetrievePropertyValue<int>("Id", getOriginalValue);
            entity.Name = RetrievePropertyValue<string>("Name", getOriginalValue);
        }

        protected override void SpecificApplyChanges(ISimpleObject entity, IDataTrasferObjectToEntityMapper dataTrasferObjectToEntityMapper)
        {
        }	 
    }
}
